using System;
using System.Data;
using System.Data.SqlClient;
using SystemFrameworks;
using Common;
using DataAccess;
using Microsoft.ApplicationBlocks.Data;

namespace BusinessRules
{
    public class SigPlanAccionAdmPerfiles
    {
        #region Propiedades

        private const String PLN_ID_PARAM = "@PLN_ID";
        private const String PER_ID_PARAM = "@PER_ID";
        private string _CadenaConexion;

        public string CadenaConexion
        {
            get { return _CadenaConexion; }
            set { _CadenaConexion = value; }
        }

        #endregion

        #region SigPlanAccionAdmPerfiles

        public SigPlanAccionAdmPerfiles(string strCadenaConecxion)
        {
            CadenaConexion = strCadenaConecxion;
        }

        #endregion

        #region ConsultarSigPlanAccionAdmPerfilesPerId

        public SigPlanAccionAdmPerfilesData ConsultarSigPlanAccionAdmPerfilesPerId(string strPerID)
        {
            SqlParameter param1 = new SqlParameter(PER_ID_PARAM, strPerID);

            SqlParameter[] parameters = { param1};
            SigPlanAccionAdmPerfilesData objSigPlanAccionAdmPerfilesData = new SigPlanAccionAdmPerfilesData();
            SqlHelper.ExecuteDataTable(CadenaConexion, CommandType.StoredProcedure, "PAS_CONSULTAR_SIG_PLAN_ACCION_ADM_PERFILES_PER_ID", objSigPlanAccionAdmPerfilesData, parameters);
            return objSigPlanAccionAdmPerfilesData;
        }

        #endregion

        #region AdicionarSigPlanAccionAdmPerfiles

        public int AdicionarSigPlanAccionAdmPerfiles(SigPlanAccionAdmPerfilesData objDT, params SqlTransaction[] objTransaction)
        {
            int resultado = 0;
            
            try
            {
                foreach (DataRow objRow in objDT.Rows)
                {
                    SqlParameter param1 = new SqlParameter(PER_ID_PARAM, objRow[SigPlanAccionAdmPerfilesData.PER_ID_FIELD]);
                    SqlParameter param2 = new SqlParameter(PLN_ID_PARAM, objRow[SigPlanAccionAdmPerfilesData.PLN_ID_FIELD]);
                    SqlParameter[] parameters = { param1, param2 };
                    if (objTransaction.Length == 0)
                    {
                        resultado = SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                              "PAS_ADICIONAR_SIG_PLAN_ACCION_ADM_PERFILES", parameters);
                    }
                    else
                    {
                        resultado = SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                           "PAS_ADICIONAR_SIG_PLAN_ACCION_ADM_PERFILES", parameters);
                    }
                    //idPerfil = Convert.ToInt32(param5.Value);
                }
            }
            catch (Exception objEx)
            {
                throw new ApplicationExceptionManager(Utilidad.TraerMensaje("gmsgErrorInsertar", "PAS_ADICIONAR_SIG_PLAN_ACCION_ADM_PERFILES"), objEx);
            }
            
            return resultado;
        }

        #endregion

        #region EliminarSigPlanAccionAdmPerfiles

        public int EliminarSigPlanAccionAdmPerfiles(int intPerID, params SqlTransaction[] objTransaction)
        {
            int resultado ;

            try
            {
                SqlParameter param1 = new SqlParameter(PER_ID_PARAM, intPerID);
                SqlParameter[] parameters = { param1};
                if (objTransaction.Length == 0)
                {
                    resultado = SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                          "PAS_ELIMINAR_SIG_PLAN_ACCION_ADM_PERFILES", parameters);
                }
                else
                {
                    resultado = SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                       "PAS_ELIMINAR_SIG_PLAN_ACCION_ADM_PERFILES", parameters);
                }
                //idPerfil = Convert.ToInt32(param5.Value);
                
            }
            catch (Exception objEx)
            {
                throw new ApplicationExceptionManager(Utilidad.TraerMensaje("gmsgErrorInsertar", "PAS_ELIMINAR_SIG_PLAN_ACCION_ADM_PERFILES"), objEx);
            }

            return resultado;
        }

        #endregion

    }
}
